<%@include file="/WEB-INF/templates/configuration.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@page import="nl.hva.web.mvcwebapp.controllers.UserController"%>

<h2>${pageTitle}</h2>
<p>${threadBody}</p>

<c:choose>
    <c:when test="${commentsSize != 0}">
        <!-- Wanneer er forums opgeslagen zijn, worden ze hier getoond -->
        <form id="newcomment" action="" method="post">
            <table class="zebra">
                <tr>
                    <th>
                        <strong>Author</strong>
                    </th>
                    <th>
                        <strong>Comment</strong>
                    </th>
                    <th>
                        <strong>Date and time</strong>
                    </th>
                    <th>
                        <strong>Console</strong>
                    </th>

                </tr>

                <c:forEach var="comments" items="${comments}">
                    <!-- Per forum wordt nu een rij aangemaakt met daarin zijn gegevens -->
                    <tr>
                        <td width="150px;">
                            ${comments.user.userName}
                        </td>
                        <td width="400px;">
                            ${comments.forumcomment_body}
                        </td>
                        <td width="250px;">
                            ${comments.timestampp}
                        </td>
                        <td width="100px;">
                            <c:choose>
                                <c:when test="${comments.user.userId == currentUserId}">
                                    <a class="icon delete" title="Delete comment" href="${url}forum/delete_comment?comment_id=${comments.forumcomment_id}&thread_id=${thread.forumThreadId}"></a>
                                    <a class="icon edit" title="Edit comment" href="${url}forum/edit_comment?comment_id=${comments.forumcomment_id}&thread_id=${thread.forumThreadId}"></a>
                                                                        
                                </c:when>
                                <c:otherwise></c:otherwise> 
                            </c:choose>
                        </td>

                    </tr>

                </c:forEach>
            
               <tr>
                   <td cosplan="4"> 
                   <td >
                        <textarea id="commentbody" name="commentbody" rows="8" cols="50" class="mceEditor"></textarea>
                        
                    </td>
                    <td>
                        <input class="submit" type="submit" value="Comment">
                    </td>
</td>
                </tr>
            </table>
        </c:when>
        <c:otherwise>
            
            <form id="newcomment" action="" method="post">
                <table class="zebra">
                    <tr>
                        <td>
                            There are no comments in this thread.
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>
                            <textarea id="commentbody" name="commentbody" rows="8" cols="50" class="mceEditor"></textarea>
                        </td>
                        <td>
                            <input class="submit" type="submit" value="Comment">
                        </td>

                    </tr>
                </table>
            </c:otherwise>

        </c:choose>

        <p>
            <a class="button" href="${url}">Go back to the forums</a>
        </p>

    </form>